package leetcode_core.leetcode_5;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月04日 11:30
 */
public class MatrixReshape {
    public int[][] matrixReshape(int[][] mat, int r, int c) {
        int m = mat.length;
        int n = mat[0].length;
        if(m == r && n == c){
            return mat;
        }
        if(m*n != r*c){
            return mat;
        }
        int[][] res = new int[r][c];
        int k = 0,z = 0;
        for(int i = 0;i<m;i++){
            for(int j = 0;j<n;j++){
                res[k][z++] = res[i][j];
                if(z == c){
                    z = 0;k++;
                }
            }
        }
        return res;
    }
}
